<template>
    <div class="doctorreviewlist">
        <Row>
            <Col :xs="24">
                <div class="margin-up-down">
                    <three
                        @changeProvince="changeProvince"
                        @changeCity="changeCity"
                        @changeArea="changeArea"
                        @changeHospital="changeHospital"
                        :province="province"
                        :city="city"
                        :area="area"
                        :hospital="hospital"
                        :hospitalType="2"
                        :isBack="isBack"
                    ></three>
                </div>
                <div class="margin-up-down">
                    <DatePicker type="daterange" v-model="filterObj.time" placement="bottom-end" format="yyyy-MM-dd" placeholder="请选择日期" separator='至' style="width: 200px"></DatePicker>
                </div>
                <div class="margin-up-down">
                    <Input class="w-input" v-model="filterObj.numb" placeholder="请输入订单号"/>                                    
                </div>
                <div class="margin-up-down" >
                    <Input class="w-input" v-model="filterObj.number" placeholder="请输入处方号"/>                                    
                </div>
                <div class="margin-up-down">
                    <Input class="w-input" v-model="filterObj.name" placeholder="请输入客户姓名"/>                                    
                </div>                               
                <div class="margin-up-down">
                    <Select class="w-select" clearable v-model="filterObj.status" :key="filterObj" placeholder="请选择处方状态">
                        <Option
                            v-for="(item,index) in statusList"
                            :value="index"
                            :key="index"
                            style='text-align:center'
                        >{{item}}</Option>
                    </Select>
                </div>
                <div class="margin-up-down">
                    <Select class="w-select" clearable v-model="filterObj.ostatus" placeholder="请选择配送类型">
                        <Option
                            v-for="(item,index) in timeList"
                            :value="index"
                            :key="index"
                            style='text-align:center'
                        >{{item}}</Option>
                    </Select>
                </div>
                <div class="filter-btn-group">
                    <Button type="primary" icon="ios-search" @click="cloudStockMonitorList(1)" class="btn"></Button>
                    <Button @click="reset" class="btn">
                        <i class = "iconfont icon-gengxin" style="font-size:14px;margin-right:5px"></i>
                    </Button>
                </div>
            </Col>
        </Row>
        <Table
            size="small"
            :columns="columns"
            :data="data1"
            @on-selection-change="selectChange"
            :loading="loading"
            no-data-text="未查询到符合条件的记录"
            border
            stripe
        >
        </Table>
        <div class="page">
            <Page :total="count" :current='pageNo' :page-size="pageSize"  show-total show-elevator @on-change="cloudStockMonitorList"/>
        </div>
    </div>
</template>
<script>
const filterObj = {
    row: 10,
    time: [],
};
import { DatePicker } from "view-design";
import three from "@/components/three";
import api from "@/api/commonApi";
import Utils from "@/utils";
export default { 
    data() {
        return {
            change:true,
            province: null,
            city: null,
            area: null,
            hospital: null,
            isBack: 1,
            searchKey: "",
            status: "",
            ostatus: "",
            tstatus: "",
            statusList: ["全部", "待支付", "待取药", "待发货", "待收货", "已完成", "已退款"],
            hospitalId: "", 
            count: 0,
            pageSize: 10,
            pageNo: 1,
            deptmentList:[],
            timeStatus: 4,
            selectTimeStatus: 1,
            cityList: [],
            data1: [],
            loading: false, 
            timeList: ['药店自取','物流配送'],
            // timeList: ['快递配送','药店配送', '线下自取'],
            columns: [
                { type: "sum", title: "排序", width: 80, align: "center",
                    render: (h, params) => {
                    let sum = (this.pageNo-1)*this.pageSize + params.index +1;
                    return h("span", sum);
                }
                },
                { title: "订单号", key: "orderNumber", align: "center" },
                { title: "处方号", key: "rxCode", align: "center" },
                { title: "客户姓名", key: "name", align: "center" },
                { title: "订单金额", key: "amt", width: 100,align: "center" },
                {
                    title: "支付方式",
                    key: "tradingChannels",
                    align: "center",
                    render: (h, params) => {
                        return '微信支付';
                    }
                },
                { title: "支付时间", key: "notifyTime", align: "center" },
                {
                    title: "配送类型",
                    key: "distributionType",
                    align: "center",
                    render: (h, params) => {
                        let status = params.row.distributionType;
                        return ['快递配送','药店配送', '线下自取'][parseInt(status)]
                        // return ['药店自取','物流配送'][parseInt(status)]
                    }
                },
                {
                    title: "订单状态",
                    key: "distributionStatus",
                    align: "center",
                    render: (h, params) => {
                        let status = params.row.distributionStatus;
                        switch (parseInt(status)) {
                        case 1:
                            return '驳回 '
                        case 2:
                            return '待审核'
                        case 3:
                            return '待复审'
                        case 4:
                            return '待支付'
                        case 5:
                            return '待取药'
                        case 6:
                            return '待发货'
                        case 7:
                            return '待收货'
                        case 8:
                            return '已完成'
                        case 9:
                            return '已作废'
                        case 10:
                            return '无效处方'
                        case 11:
                            return '已退费'
                        case 12:
                            return '审核中'
                        }
                    }
                },
                { title: "所属药店", key: "hospitalName", align: "center" },
                {
                    title: "设置",
                    key: "iOperate",
                    width: 100,
                    align: "center",
                    render: (h, params) => {
                        return h("div", [
                        h(
                            "a",
                            {
                            props: {
                                type: "primary",
                                size: "small"
                            },
                            on: {
                                click: () => {
                                this.handleDetail(params);
                                }
                            }
                            },
                            "查看详情 "
                        )
                        ]);
                    }
                }
            ],
            filterObj: this.deepClone(filterObj)
        };
    },
    components: {
        DatePicker,
        three
    },
    created() {
        this.province = this.$route.query.province
            ? parseInt(this.$route.query.province)
            : null;
        this.city = this.$route.query.city
            ? parseInt(this.$route.query.city)
            : null;
        this.area = this.$route.query.area
            ? parseInt(this.$route.query.area)
            : null;
        this.hospital = this.$route.query.hospital
            ? this.$route.query.hospitals
            : null;
        this.isBack = this.$route.query.isBack
            ? parseInt(this.$route.query.isBack)
            : 1;
        // this.filterObj.startDate = this.GetDate(-2);
        // // this.startDate='2019-02-07'
        // this.filterObj.endDate = this.GetDate(0);
    },
    mounted() {
        let pageNo = this.$route.query.pageNo;
        pageNo = pageNo ? pageNo : 1;
        //上来就加载第一页数据
        this.cloudStockMonitorList(pageNo);
        // this.loadingDepartment();
    },
    methods: {
        deepClone(obj) {
            return JSON.parse(JSON.stringify(obj));
            this.ordersSearchPage();
        },
        reset() {
            this.filterObj = this.deepClone(filterObj);
            this.province = null,
            this.city = null,
            this.area = null,
            this.val = '',
            this.hospital= '',
            this.cloudStockMonitorList(1);
        },
        changeHospital(val){
            this.hospital = val;
        },
        changeProvince(val) {
            this.province = val;            
        },
        changeCity(val) {
            this.city = val;           
        },
        changeArea(val) {
            this.area = val;
        },
        handleDetail(record) {
            // 查看详情
            if (record.row.distributionStatus === 0 || record.row.distributionStatus === 1 || record.row.distributionStatus === 2 || record.row.distributionStatus === 3) {
                return this.$Message.error("无订单详情");
            }
            if (record.row.distributionType === 0) {
                this.functionJS.queryNavgationTo(this, "/index/prescription/ordersearch/logistics", {id: record.row.id});
            } else {
                this.functionJS.queryNavgationTo(this, "/index/prescription/ordersearch/review", {id: record.row.id});
            }
        },
        //加载列表数据
        cloudStockMonitorList(pageNo) {
            this.pageNo = pageNo;
            this.ishandlehome()
        },
        ishandlehome() {
            let me = this
            var params = {};
            params.provinceCode = this.province ? this.province : null;//省
            params.cityCode = this.city ? this.city : null;//市
            params.areaCode = this.area ? this.area : null;//区
            params.hospitalId = this.hospital ? this.hospital : null;
            let a = this.filterObj.name;
            params.name = a==''?null:a//客户姓名
            // params.name = a.trim() ? a.trim() : null//客户姓名
            params.rxCode = this.filterObj.number//处方号
            params.orderNumber = this.filterObj.numb//订单号
            // params.distributionStatus = this.filterObj.status//处方状态
            if(this.filterObj.status===0){//处方状态
                params.distributionStatus = ''
            }else if(this.filterObj.status==1){
                params.distributionStatus = 4
            }else if(this.filterObj.status==2){
                params.distributionStatus = 5
            }else if(this.filterObj.status==3){
                params.distributionStatus = 6
            }else if(this.filterObj.status==4){
                params.distributionStatus = 7
            }else if(this.filterObj.status==5){
                params.distributionStatus = 8
            }else if(this.filterObj.status==6){
                params.distributionStatus = 11
            }else if(this.filterObj.status==7){
                params.distributionStatus = 13
            }else{
                params.distributionStatus = ''
            }
            if(this.filterObj.ostatus===0){
                params.takeMedicineType = 0     //线下自取
            }else if(this.filterObj.ostatus==1){
                params.takeMedicineType = 1    //药店配送
            } else if(this.filterObj.ostatus== '' ){
                params.takeMedicineType = ''   
            }
            console.log(this.pageNo)
            params.page = this.pageNo;
            params.size = this.pageSize;
            if(this.filterObj.time[0]==''){
                params.minData = ''
                params.maxData = ''
            }else{
                params.minData = Utils.getNowDateBySpecialFormat(this.filterObj.time[0])
                params.maxData = Utils.getNowDateBySpecialFormat(this.filterObj.time[1])
            }
            this.$axios.post(api.findPharmaceOrderPage, params).then(resp => {
                me.data1 = resp.data.object.records
                this.count = resp.data.object.total
            })
            .catch(err => {
                console.log(err);
            });
        },
    }
};
</script>
<style lang="less" scoped>
.doctorreviewlist {
    padding: 10px;
    width: 100%;
    background: #ffffff;
    box-sizing: border-box;
    .w-select {
        width: 140px;
    }
    .w-input {
        width: 220px;
    }
    .m-table {
        margin: 10px 0;
        // margin-top: 20px;
        .page-wrapper {
            display: flex;
            justify-content: space-between;
            .des {
                display: flex;
                align-items: center;
                .select {
                    width: 50px;
                }
            }
        }   
    }
    .filter-btn-group {
        display: inline-block;
        margin: 10px 10px 10px 0;
        flex: 0 0 auto;
        .btn {
            width: 58px;
            height: 32px;
        }
    }
    .margin-up-down {
        display: inline-block;
        margin: 10px 0;
        span{
            margin:0 5px 0 10px;
        }
    }
    .page {
        width: 100%;
        margin: 10px auto;
        text-align: center;
    }
}
</style>